package leetcode;

public class ListNode {
    int val;
    ListNode next;

    ListNode(int x) {
        val = x;
        next = null;
    }

    ListNode(int x, ListNode next) {
        val = x;
        this.next = next;
    }

    public static ListNode ln(int[] x) {
        if (x.length < 1) return null;
        ListNode first = new ListNode(x[0]);
        ListNode node = first;
        for (int i = 1; i < x.length; i++) {
            node.next = new ListNode(x[i]);
            node = node.next;
        }
        return first;
    }

    public static void print(ListNode node) {
        System.out.print('[');
        while (node != null) {
            System.out.print(node.val);
            System.out.print(',');
            node = node.next;
        }
        System.out.print(']');
    }
}